

function say() {
    alert("LC:219. 存在重复元素 II");
}
say();


/**
 * @param {number[]} nums
 * @param {number} k
 * @return {boolean}
 */
var containsNearbyDuplicate = function (nums, k) {

    //1:50-2:05
    var hashMap = {} //key:nums val:下标
    for(var i = 0; i < nums.length; i++){
        var idxVal = hashMap[nums[i]]
        if(typeof(idxVal) == 'undefined') { //插入
            hashMap[nums[i]] = i
        }else if(i - idxVal <= k){
            return true
        }else { //更新
            hashMap[nums[i]] = i
        }
    }
    return false
};
